package course_9_2.eg;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class TestA {
    public static void main(String[] args) {
        File file;
        Scanner scanner,fileScanner;
        while(true){
            try {
                System.out.println("File name:");
                scanner = new Scanner(System.in);
                file = new File(scanner.next());
                fileScanner = new Scanner(file);
                scanner.close();
                break;
            } catch (NullPointerException nullPointerException) {
                System.out.println("You must enter a file name");
            } catch (FileNotFoundException fileNotFoundException){
                System.out.println("Invalid filename");
            }
        }
        while (true){
            try{
                System.out.println(fileScanner.next());
            }catch (NoSuchElementException noSuchElementException){
                fileScanner.close();
                break;
            }
        }
    }
}
